import { observable, action } from "mobx";
import * as api from "../api/api";
import request from "../utils/request";
import { LoadHoc, loading } from '../hoc/loadHoc';

export default class UserStore extends LoadHoc {

  /**
   * 获取验证码
   */
  @observable smsCode:string = ''
  @loading @action async getSmsCode(params: {
    form: api.YNJWTUsersFormSendCodeForm;
    callback?: (smsCode: string) => void;
  }){
    const { form, callback } = params;
    const smsCode = await request(api.AppuserApiFetchParamCreactor.appuserSendCodeAsync({
      form
    }));
    this.smsCode = smsCode;
    callback&&callback(smsCode)
  }

  /**
   * 用户登录
   */
  @loading @action async userLogin(params: {
    form: api.YNJWTUsersFormUserAppLoginForm,
    callback: (res) => void
  }){
    const { form, callback } = params
      const userLoginRes = await request(api.AppuserApiFetchParamCreactor.appuserLoginAsync({
      form
    }));
    callback&&callback(userLoginRes)
  }
  /**
   * 注册第一步-输入手机号获取验证码
   */
  @observable registerStepOne: api.YNJWTUsersVOUserMiniVO  = {};
  /**
   * 注册第一步
   */
  @loading @action async registerStepOneF(params: {
    form: api.YNJWTUsersFormRegisterFrom;
    callback?: (registerStepOne: api.YNJWTUsersVOUserMiniVO) => void;
  }) {
    const { form, callback } = params;
    const registerStepOne = await request(api.AppuserApiFetchParamCreactor.appuserRegisterAsync({
      form
    }));
    this.registerStepOne = registerStepOne;
    callback&&callback(registerStepOne);
  }

  /**
   * 用户登出
   */
  @loading @action async logout(params: {
    callback: (res) => void
  }){
    const { callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserLogoutAsync({}));
    callback&&callback(res)
  }
  /**
   * 获取用户信息
   * 该接口返回的token为空
   */
  @observable userInfo: api.YNJWTUsersVOUserMiniVO  = {};
  @loading @action async getUserInfo(params: {
    callback: (res: api.YNJWTUsersVOUserMiniVO) => void
  }){
    const { callback } = params
    const userInfo = await request(api.AppuserApiFetchParamCreactor.appuserGetUserInfoAsync({
    }));
    this.userInfo=userInfo
    callback&&callback(userInfo)
  }

  /**
   * 设置密码
   */
  @loading @action async setPassword(params: {
    form: api.YNJWTUsersFormSetPasswordForm,
    callback: (res: api.YNJWTUsersVOUserMiniVO) => void
  }){
    const { form,callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserSetPasswordAsync({
      form,
    }));
    callback&&callback(res)
  }

  /**
   * 会员中心修改密码
   */
  @loading @action async updateUserPassword(params: {
    form: api.YNJWTUsersFormChangePasswordForm,
    callback: (res) => void
  }){
    const { form,callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserUpdateUserPasswordAsync({
      form,
    }));
    callback&&callback(res)
  }

  /**
   * 获取用户佣金
   */
  @observable userCommisions: api.YNJWTUsersVOUserBenifitsVO = {};

  @loading @action async getUserCommisions(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOUserBenifitsVO) => void
  }){
    const { pageIndex,pageSize,callback } = params
    const userCommisions = await request(api.AppuserApiFetchParamCreactor.appuserGetUserCommisionsAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
  }));
    this.userCommisions=userCommisions
    callback&&callback(userCommisions)
  }

  /**
   * 获取提现明细
   */
  @observable userCashes: api.YNJWTUsersVOUserCashVO = {};

  @loading @action async getUserCashes(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOUserCashVO) => void
  }){
    const { pageIndex,pageSize,callback } = params
    const userCashes = await request(api.AppuserApiFetchParamCreactor.appuserGetUserCashesAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.userCashes=userCashes
    callback&&callback(userCashes)
  }

  /**
   * 获取用户提现手续费率
   */
  @loading @action async getCashService(params: {
    callback: (res: api.YNJWTUsersVOConfigVO) => void
  }){
    const { callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserGetCashServiceAsync({
    }));
    callback&&callback(res)
  }

  /**
   * 获取用户收益记录
   */
  @loading @action async getUserBenifitsStatistics(params: {
    callback: (res: api.YNJWTUsersVOBenifitsStatistics) => void
  }){
    const { callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserGetUserBenifitsStatisticsAsync({
    }));
    callback&&callback(res)
  }

  /**
   * 用户提现
   */
  @loading @action async cash(params: {
    form:api.YNJWTUsersFormUserCashForm,
    callback: (res) => void
  }){
    const { form,callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserCashAsync({
      form
    }));
    callback&&callback(res)
  }

  /**
   * 获取推广用户
   */
  @observable spreadUsers: api.YNJWTUsersVOUserVO = {};

  @loading @action async getSpreadUsers(params: {
    formLevel: number,
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOUserVO) => void
  }){
    const { formLevel,pageIndex,pageSize,callback } = params
    const spreadUsers = await request(api.AppuserApiFetchParamCreactor.appuserGetSpreadUsersAsync({
      formLevel,
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.spreadUsers=spreadUsers
    callback&&callback(spreadUsers)
  }

  /**
   * 获取推广用户数量
   */
  @observable userShareCount: api.YNJWTUsersVOShareCountVO = {};

  @loading @action async getUserShareCount(params: {
    callback: (res: api.YNJWTUsersVOShareCountVO) => void
  }){
    const { callback } = params
    const userShareCount = await request(api.AppuserApiFetchParamCreactor.appuserGetUserShareCountAsync({
    }));
    this.userShareCount=userShareCount
    callback&&callback(userShareCount)
  }

  /**
   * 获取推广用户下级成员
   */
  @observable userShareUsers: api.YNJWTUsersVOUserVO = {};

  @loading @action async getUserShareUsers(params: {
    formUserId: number,
    formLevel?: number,
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOUserVO) => void
  }){
    const { formUserId,formLevel,pageIndex,pageSize,callback } = params
    const userShareUsers = await request(api.AppuserApiFetchParamCreactor.appuserGetUserShareUsersAsync({
      formUserId,
      formLevel,
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.userShareUsers=userShareUsers
    callback&&callback(userShareUsers)
  }

  /**
   * 获取用户收藏列表
   */
  @observable userFavorites: api.YNJWTUsersVOUserCollectionVO = {};

  @loading @action async getUserFavorites(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOUserCollectionVO) => void
  }){
    const { pageIndex,pageSize,callback } = params
    const userFavorites = await request(api.AppuserApiFetchParamCreactor.appuserGetUserFavoritesAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.userFavorites=userFavorites
    callback&&callback(userFavorites)
  }

  /**
   * 获取用户银行卡
   */
  @observable userCards: api.YNJWTUsersVOUserCardVO = {};

  @loading @action async getUserCards(params: {
    callback: (res: api.YNJWTUsersVOUserCardVO) => void
  }){
    const { callback } = params
    const userCards = await request(api.AppuserApiFetchParamCreactor.appuserGetUserCardsAsync({}));
    this.userCards=userCards
    callback&&callback(userCards)
  }

  /**
   * 获取平台支持的银行卡
   */
  @observable banks: api.YNJWTUsersVOBankVO = {};

  @loading @action async getBanks(params: {
    callback: (res: api.YNJWTUsersVOBankVO) => void
  }){
    const { callback } = params
    const banks = await request(api.AppuserApiFetchParamCreactor.appuserGetBanksAsync({}));
    this.banks=banks
    callback&&callback(banks)
  }

  /**
   * 保存银行卡
   */
  @loading @action async saveUserCard(params: {
    form: api.YNJWTUsersFormUserCardForm,
    callback: (res) => void
  }){
    const { form, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserSaveUserCardAsync({
      form
    }));
    callback&&callback(res)
  }

  /**
   *删除用户银行卡
   */
  @loading @action async removeUserCard(params: {
    id: number,
    callback: (res) => void
  }){
    const { id, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserRemoveUserCardAsync({
      form: {
        id
      }
    }));
    callback&&callback(res)
  }

  /**
   * 修改用户信息
   */
  @loading @action async modifyUser(params: {
    form: api.YNJWTUsersFormUserModifiedForm,
    callback: (res) => void
  }){
    const { form, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserModifyUserAsync({
      form
    }));
    callback&&callback(res)
  }

  /**
   * 获取用户收货地址
   */
  @observable userAddresses: api.YNJWTUsersVOUserAddressVO = {};

  @loading @action async getUserAddresses(params: {
    callback: (res: api.YNJWTUsersVOUserAddressVO) => void
  }){
    const { callback } = params
    const userAddresses = await request(api.AppuserApiFetchParamCreactor.appuserGetUserAddressesAsync({}));
    this.userAddresses = userAddresses
    callback&&callback(userAddresses)
  }

  /**
   *保存用户收货地址
   */
  @loading @action async saveUserAddress(params: {
    form:api.YNJWTUsersFormUserAddressForm,
    callback: (res) => void
  }){
    const { form,callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserSaveUserAddressAsync({
      form
    }));
    callback&&callback(res)
  }

  /**
   * 删除用户收货地址
   */
  @loading @action async removeUserAddress(params: {
    id: api.YNJWTCommonSingleIdSystemInt64,
    callback: (res) => void
  }){
    const { id, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserRemoveUserAddressAsync({
      form: {
        id
      }
    }));
    callback&&callback(res)
  }

  /**
   * 设置用户默认收货地址
   */
  @loading @action async setDefaultUserAddress(params: {
    id: api.YNJWTCommonSingleIdSystemInt64,
    callback: (res) => void
  }){
    const { id, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserSetDefaultUserAddressAsync({
      form: {
        id
      }
    }));
    callback&&callback(res)
  }

  /**
   * 用户收藏
   */
  @loading @action async saveUserCollection(params: {
    form: {
      informationsId: number,
      dynamicsId: number,
      courseInformationId: number,
      userCollectionType: number,
    },
    callback: (res) => void
  }){
    const { form, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserSaveUserCollectionAsync({
     form
    }),'',false);
    callback&&callback(res)
  }

  /**
   * 用户取消收藏
   */
  @loading @action async cancelUserCollection(params: {
    form: {
      userCollectionType: api.YNJWTUsersFormCancelFormUserCollectionTypeEnum,
      id: number
    },
    callback: (res) => void
  }){
    const { form, callback } = params
    const res = await request(api.AppuserApiFetchParamCreactor.appuserCancelUserCollectionAsync({
      form
    }), '', false);
    callback&&callback(res)
  }

  /**
   * 获取用户积分
   */
  @observable userPointRecords: api.YNJWTUsersVOUserPointsVO = {};

  @loading @action async getUserPointRecords(params: {
    userPointsType: number,
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOUserPointsVO) => void
  }){
    const {  userPointsType,pageIndex,pageSize,callback } = params
    const userPointRecords = await request(api.AppuserApiFetchParamCreactor.appuserGetUserPointRecordsAsync({
      formUserPointsType: userPointsType,
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.userPointRecords = userPointRecords
    callback&&callback(userPointRecords)
  }

  /**
   * 我的发布
   */
  @observable myRelease: api.YNJWTTalentCenterVOInformationsVO = {};

  @loading @action async getMyRelease(params: {
    publicationType: number,
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTTalentCenterVOInformationsVO) => void
  }){
    const {  publicationType,pageIndex,pageSize,callback } = params
    const myRelease = await request(api.AppuserApiFetchParamCreactor.appuserGetMyReleaseAsync({
      formPublicationType: publicationType,
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.myRelease = myRelease
    callback&&callback(myRelease)
  }


  /**
   * 我的申请
   */
  @observable myApplication: api.YNJWTFinancialCenterVOCompanyTaxReturnVO = {};

  @loading @action async getMyApplication(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTFinancialCenterVOCompanyTaxReturnVO) => void
  }){
    const {  pageIndex,pageSize,callback } = params
    const myApplication = await request(api.AppuserApiFetchParamCreactor.appuserGetMyApplicationAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.myApplication = myApplication
    callback&&callback(myApplication)
  }

  /**
   * 我的课程
   */
  @observable myCourseInfo: api.YNJWTUsersVOMyCourseVO = {};

  @loading @action async getMyCourseInfo(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOMyCourseVO) => void
  }){
    const {  pageIndex,pageSize,callback } = params
    const myCourseInfo = await request(api.AppuserApiFetchParamCreactor.appuserGetMyCourseInfoAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.myCourseInfo = myCourseInfo
    callback&&callback(myCourseInfo)
  }

  /**
   * 问答
   */
  @observable doubtAnswers: api.YNJWTUsersVOScrollingVO = {};

  @loading @action async getDoubtAnswers(params: {
    callback: (res: api.YNJWTUsersVOScrollingVO) => void
  }){
    const { callback } = params
    const doubtAnswers = await request(api.AppuserApiFetchParamCreactor.appuserGetDoubtAnswersAsync({
    }));
    this.doubtAnswers = doubtAnswers
    callback&&callback(doubtAnswers)
  }

  /**
   * 问答详情
   */
  @observable doubtAnswer: api.YNJWTUsersVOScrollingVO = {};

  @loading @action async getDoubtAnswer(params: {
    formId:number,
    callback: (res: api.YNJWTUsersVOScrollingVO) => void
  }){
    const { formId,callback } = params
    const doubtAnswer = await request(api.AppuserApiFetchParamCreactor.appuserGetDoubtAnswerAsync({
      formId
    }));
    this.doubtAnswer = doubtAnswer
    callback&&callback(doubtAnswer)
  }

  /**
   * 查询代理升级费用
   */
  @observable agencyAmount: api.YNJWTUsersVOAgencyAmountVO = {};
  @loading @action async getAgencyAmount(params: {
    callback: (res:api.YNJWTUsersVOAgencyAmountVO) => void
  }){
    const { callback } = params
    const agencyAmount = await request(api.AppuserApiFetchParamCreactor.appuserGetAgencyAmountAsync({
    }));
    this.agencyAmount = agencyAmount
    callback&&callback(agencyAmount)
  }

  /**
   * 代理升级购买
   */
  @loading @action async agencyApply(params: {
    form: api.YNJWTUsersFormAgencyApplyForm,
    callback: (res: string) => void
  }){
    const {  form,callback } = params
    const userBuyAgencyLeval = await request(api.AppuserApiFetchParamCreactor.appuserAgencyApplyAsync({
      form
    }));
    this.userBuyAgencyLeval = userBuyAgencyLeval
    callback&&callback(userBuyAgencyLeval)
  }

  /**
   * 查询代理升级购买记录
   */
  @observable userBuyAgencyLeval: api.YNJWTUsersVOAgencyApplyVO = {};

  @loading @action async getUserBuyAgencyLeval(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOAgencyApplyVO) => void
  }){
    const {  pageIndex,pageSize,callback } = params
    const userBuyAgencyLeval = await request(api.AppuserApiFetchParamCreactor.appuserGetUserBuyAgencyLevalAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.userBuyAgencyLeval = userBuyAgencyLeval
    callback&&callback(userBuyAgencyLeval)
  }

  /**
   * 用户注册协议
   */
  @observable userRegistAgreement: api.YNJWTUsersVOConfigVO = {};

  @loading @action async getUserRegistAgreement(params: {
    callback: (res: api.YNJWTUsersVOConfigVO) => void
  }){
    const { callback } = params
    const userRegistAgreement = await request(api.AppuserApiFetchParamCreactor.appuserGetUserRegistAgreementAsync({
    }));
    this.userRegistAgreement = userRegistAgreement
    callback&&callback(userRegistAgreement)
  }

  /**
   * 用户参与的公益众筹项目
   */
  @observable allUserCrowdFunding: api.YNJWTUsersVOCrowdFundingVO = {};

  @loading @action async getAllUserCrowdFunding(params: {
    pageIndex: number,
    pageSize: number,
    callback: (res: api.YNJWTUsersVOCrowdFundingVO) => void
  }){
    const { pageIndex,pageSize,callback } = params
    const allUserCrowdFunding = await request(api.AppuserApiFetchParamCreactor.appuserGetAllUserCrowdFundingAsync({
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount:pageSize
    }));
    this.allUserCrowdFunding = allUserCrowdFunding
    callback&&callback(allUserCrowdFunding)
  }

  /**
   * 企业认证
   */
  @loading @action async saveEnterpriseCertification(params: {
    form: {
      companyName: string,
      natureOfTheFirm: string,
      enterpriseScale: string,
      certificateIMG: string,
      area: string,
      contactsName: string,
      phoneNumnber: string,
      wechatNumber: string,
      qqNumber: string,
      enterpriseIntroduce: string,
      id?: string
    },
    callback: (res: api.YNJWTUsersVOAgencyApplyVO) => void
  }){
    const {  form,callback } = params
    const userBuyAgencyLeval = await request(api.AppuserApiFetchParamCreactor.appuserSaveEnterpriseCertificationAsync({
      form
    }));
    this.userBuyAgencyLeval = userBuyAgencyLeval
    callback&&callback(userBuyAgencyLeval)
  }

  /**
   * 获取企业认证需不需
   */
  @loading @action async getUserEnterpriseCertificationInfo(params: {
    callback: (res: api.YNJWTUsersVOEnterpriseCertificationVO) => void
  }){
    const { callback } = params
    const userEnterpriseCertificationInfo = await request(api.AppuserApiFetchParamCreactor.appuserGetUserEnterpriseCertificationInfoAsync({
    }));
    callback&&callback(userEnterpriseCertificationInfo)
  }
}
